Skip to content
本页内容

Validation (对象)

代表工作表区域的数据有效性规则。

说明

使用 Validation 属性可返回 Validation 对象。

示例

python
#本示例更改单元格 E5 的数据有效性验证
def test():
    Application.Range("E5").Validation.Modify(xlValidateList, xlValidAlertStop, None, "=$A$1:$A$10")

使用 Add方法可将数据有效性添加到某个区域并创建一个新的 Validation 对象。

python
#本示例为 E5 单元格添加数据有效性验证
def test():
    validation = Application.Range("E5").Validation
    validation.Add(xlValidateWholeNumber, xlValidAlertStop, xlBetween, "5", "10")
    validation.InputTitle = "Integers"
    validation.ErrorTitle = "Integers"
    validation.InputMessage = "Enter an integer from five to ten"
    validation.ErrorMessage = "You must enter a number from five to ten"